package org.amse.Archiver.algorithm;
import java.io.FileInputStream;
import java.io.IOException;
public class Statistic {
    private final FileInputStream myStream;
	private static final int LENGTH_ARRAY = 256;
    private int [] myCharArray = new int [LENGTH_ARRAY];
    private int mySymNum = 0;
    
	public Statistic (FileInputStream inStream) {
	    myStream = inStream;
	}
    
	public void calcFrequency() throws IOException {
	   int ch;
	   while ((ch = myStream.read()) != -1) { 
           mySymNum++;
		   myCharArray[ch]++;
		}
    }
	
	public int[] getStatistic() {
	    return myCharArray;
	}
	
	public int getSize() {
		return LENGTH_ARRAY;
	}
	
	public int getFileSize() {
		return mySymNum;
	}
	
	public String toString() {		
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < LENGTH_ARRAY; i++) {
		    if (myCharArray[i] != 0) {
		    	sb.append(i + "(" + myCharArray[i] + "); \n");
			} 
		}
		return sb.toString();
	}
}
